using System;
using Microsoft.Xna.Framework;
using Core;

namespace SolarWinds.Transitions
{
    public class WipeTransition : Transition
    {
        public Direction Direction = Direction.BottomToTop;

        public WipeTransition(Game game)
            : base(game)
        {
        }

        protected override void Update(float progress)
        {
            // nonlinear mapping -> looks better
            progress = (float)Math.Sin(progress * 0.5 * Math.PI);

            int width = Game.Window.ClientBounds.Width;
            int height = Game.Window.ClientBounds.Height;
            Rectangle rect = Screen.CropRectangle;

            if (Mode == BlendModes.In)
            {
                switch (Direction)
                {
                    case Direction.LeftToRight:
                        rect.Width = (int)(width * progress);
                        break;
                    case Direction.RightToLeft:
                        rect.X = (int)(width * (1 - progress));
                        rect.Width = (int)(width * progress);
                        break;
                    case Direction.TopToBottom:
                        rect.Height = (int)(height * progress);
                        break;
                    case Direction.BottomToTop:
                        rect.Y = (int)(height * (1 - progress));
                        rect.Height = (int)(height * progress);
                        break;
                    default: break;
                }    
            }
            else if (Mode == BlendModes.Out)
            {
                progress = (1.0f - progress);

                switch (Direction)
                {
                    case Direction.RightToLeft:
                        rect.Width = (int)(width * progress);
                        break;
                    case Direction.LeftToRight:
                        rect.X = (int)(width * (1 - progress));
                        rect.Width = (int)(width * progress);
                        break;
                    case Direction.BottomToTop:
                        rect.Height = (int)(height * progress);
                        break;
                    case Direction.TopToBottom:
                        rect.Y = (int)(height * (1 - progress));
                        rect.Height = (int)(height * progress);
                        break;
                    default: break;
                }                    
            }

            Screen.CropRectangle = rect;
        }
    }
}